package com.wsj.web.action.BmPicType;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wsj.dao.IBmPicTypeDao;
import com.wsj.service.admin.bmPicType.impl.IBmPicTypeServ;
import com.wsj.util.exception.BusinessException;
import com.wsj.util.tool.StringUtil;
import com.wsj.web.form.BmPicType.BmPicTypeForm;
import com.wsj.web.vo.gouwuxitong.BmPicType;

public class BmPicTypeAction extends DispatchAction{
	private IBmPicTypeServ bmPicTypeServImpl;
	public ActionForward add(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response) throws BusinessException{
		
		BmPicTypeForm bmPicTypeForm=(BmPicTypeForm)form;
		BmPicType bmPicType=new BmPicType();
		
		bmPicType.setNames(bmPicTypeForm.getName());
		boolean b=this.getBmPicTypeServImpl().saveBmPicType(bmPicType);
		List BmPicTypelist=this.getBmPicTypeServImpl().loadAllBmPicType();
		request.setAttribute("BmPicTypelist", BmPicTypelist);
		if(b){
			request.setAttribute("add_succ", "<script>alert('添加成功！');</script>");
			
			bmPicTypeForm.setName("");
			return mapping.findForward("add_succ");
		}
		return null;
		}
	public ActionForward del(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BusinessException{
		     
		try{
		      String[] idStr = request.getParameterValues("checkboxparam");
		      int[] intId = StringUtil.changeStrArrayToIntArray(idStr);
		      if(intId!=null){
		    	  for(int i=0;i<intId.length;i++){
		    		  this.getBmPicTypeServImpl().deleteBmPicType(intId[i]);
		    	  }
		  		List BmPicTypelist=this.getBmPicTypeServImpl().loadAllBmPicType();
				request.setAttribute("BmPicTypelist", BmPicTypelist);
		    	  request.setAttribute("del_successfully", "<script>alert('删除成功')</script>");
		      }
		}catch(Exception ex){
			log.error("异常发生--deleteBmPicType--",ex); 
			throw new RuntimeException();
		} 
		
	     return mapping.findForward("delete_successfully");
	}
	
	
	public ActionForward toupdate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BusinessException{
			
			BmPicType bmPicType=new BmPicType();
			bmPicType=this.bmPicTypeServImpl.loadBmPicTypeById(Integer.valueOf(request.getParameter("id")));

			request.setAttribute("id", bmPicType.getId());
			request.setAttribute("name", bmPicType.getNames());

			
			
			return mapping.findForward("toupdat");
			}
	
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BusinessException{
		
		    BmPicTypeForm bmPicTypeForm=(BmPicTypeForm)form;
			
			BmPicType bmPicType=new BmPicType();
			bmPicType.setId(Integer.valueOf(request.getParameter("id")));
			bmPicType.setNames(bmPicTypeForm.getName());
			boolean b=this.bmPicTypeServImpl.updateBmPicType(bmPicType);
			if(b){
		  		List BmPicTypelist=this.getBmPicTypeServImpl().loadAllBmPicType();
				request.setAttribute("BmPicTypelist", BmPicTypelist);
		    	request.setAttribute("update_successfully", "<script>alert('修改成功')</script>");
		    	bmPicTypeForm.setName("");
		    	return mapping.findForward("updat_succ");
			}
			
			

			return null;
			}
	
	
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BusinessException{
		
  		List BmPicTypelist=this.getBmPicTypeServImpl().loadAllBmPicType();
		request.setAttribute("BmPicTypelist", BmPicTypelist);
		return mapping.findForward("list");

	}
	
	
	public IBmPicTypeServ getBmPicTypeServImpl() {
		return bmPicTypeServImpl;
	}
	public void setBmPicTypeServImpl(IBmPicTypeServ bmPicTypeServImpl) {
		this.bmPicTypeServImpl = bmPicTypeServImpl;
	}


	

}
